<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        var i = 0;
        while (i < 5) {
            var o = 0;
            while (o < 5 - i - 1) {
                o++;
                document.write("$");
            }
            var k = 0;
            while (k <= i) {
                k++;
                document.write("8");
            }
            document.write("<br>");
            i++;
        }

        var a = 0;
        do {
            var b = 0;
            do {
                b++;
                document.write("$");
            } while (b < 5 - a - 1);

            var c = 0;
            do {
                c++;
                document.write("8");
            } while (c <= a)

            a++;
            document.write("<br>")
        } while (a < 5)
    </script>
</body>

</html>